package pl.ydp.components.mathcell.mathrecognizer.geometry
{
	
	public class VectorDirection
	{
		
		public static function formAngle(angle:Number):Number {
			
			var angle2:Number = angle + 360/16;
			if (angle2 > 360){
				angle2 -= 360;
			} else if (angle2 < 0){
				angle2 += 360;
			}
			
			return Math.floor(angle2 / 360 * 8);
		}
		
		public static function getReversed(_dir:Number):Number{
			if (_dir < 4){
				return _dir + 4;
			} else {
				return _dir - 4;
			}
		}
		
		public static function add(d1:Number, d2:Number):Number{
			var d:Number = d1+d2;
			if (d > MAX){
				d -= MAX;
			}
			return d;
		}
		
		public static function findDifference(d1:Number, d2:Number):Number{
			var output:Number = d1-d2;
			if (output == MAX){
				output = -1;
			} else if (output == -MAX){
				output = 1;
			}
			return output;
		}
		
		public static function findDifferenceAbs(d1:Number, d2:Number):Number{
			var output:Number = Math.abs(d1-d2);
			if (output == MAX){
				output = 1;
			} else if (output == -MAX){
				output = 1;
			}
			return output;
		}
		
		public static function isBetween(base:Number, begin:Number, end:Number):Boolean{
			
			if (end >= begin){
				
				return (base >= begin  &&  base <= end);
				 
			} else {
				
				return (!(base >= begin  &&  base <= end));
			}
			
			return false;
		}
				
		public static const UNKNOWN:Number = -1;
		public static const DIR0:Number = 0;
		public static const DIR1:Number = 1;
		public static const DIR2:Number = 2;
		public static const DIR3:Number = 3;
		public static const DIR4:Number = 4;
		public static const DIR5:Number = 5;
		public static const DIR6:Number = 6;
		public static const DIR7:Number = 7;
		
		public static const COUNT:Number = 8;
		public static const MIN:Number = 0;
		public static const MAX:Number = 7;
		public static const REVERSED_BEGIN:Number = 4;
		

	}
}